package cn.shop.merchant.controller.user;

import cn.shop.merchant.service.BackSettingService;
import cn.shop.transcation.backSetting.entity.BackSetting;
import cn.shop.utils.ApiResult;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static cn.shop.utils.constant.SystemSettingConstant.MERCHANT_GATEWAY_URL;
import static cn.shop.utils.constant.SystemSettingConstant.MERCHANT_INSTRUCTIONS;

/**
 * 主页接口
 *
 * @author : 李一涵
 * @date : Created in 2022/5/19 19:45
 * @description :
 */
@RestController
@RequestMapping("/home")
public class HomeController {

    @Resource
    private BackSettingService settingService;


    /**
     * 获取配置
     *
     * @return 返回结果
     */
    @GetMapping("/setting")
    public ApiResult<Map<String, Object>> setting() {
        LambdaQueryWrapper<BackSetting> query = Wrappers.<BackSetting>lambdaQuery()
                .in(BackSetting::getKey, Arrays.asList(MERCHANT_GATEWAY_URL, MERCHANT_INSTRUCTIONS));
        List<BackSetting> list = settingService.list(query);
        Map<String, Object> map = list.stream().collect(Collectors.toMap(BackSetting::getKey, BackSetting::getValue));
        return ApiResult.success(map);
    }

}
